const jwt = require('jsonwebtoken')
const fs = require('fs')
const path = require('path')
class JwtHandler {
  async sign(username) {
    const privateKey = await fs.readFileSync(path.resolve(__dirname, '../keys/rsa_private_key.pem'))
    return jwt.sign({ username }, privateKey, { algorithm: 'RS256'})
  }
  async verify(token) {
    const publicKey = await fs.readFileSync(path.resolve(__dirname, '../keys/rsa_public_key.pem'))
    return jwt.verify(token, publicKey)
  }
}
module.exports = JwtHandler